﻿using System;
using System.Windows.Media.Imaging;
using SomethingSpacial.CustomControls;
using SomethingSpacial.Model;
using SomethingSpacialClassLib.Web;
using System.Collections.ObjectModel;
using System.ServiceModel.DomainServices.Client;

namespace SomethingSpacial.ViewModel
{
    public class EventFeedbackViewModel : ViewModelBase
    {
        private EventFeedbackModel MyModel = new EventFeedbackModel();
        private SomethingSpacialContext domainContext;
        private SomethingSpacialContext DomainContext
        {
            get
            {
                if (domainContext == null)
                    domainContext = new SomethingSpacialContext();
                return domainContext;
            }
        }
        LoadOperation LoadEventFeedback;

        public EntitySet<SomethingSpacialClassLib.Web.EventFeedback> EventFeedback
        {
            get
            {
                return (EntitySet<SomethingSpacialClassLib.Web.EventFeedback>)DomainContext.EventFeedbacks;
            }
            //No set, it is a read-only property.
        }

        #region "ViewModel Methods"

        public void loadEventFeedback(int EventID)
        {
            LoadEventFeedback = DomainContext.Load(DomainContext.GetAllEventFeedbacksQuery(EventID));
        }

        public void AddEventFeedback(EventFeedback EventFeedbackNew)
        {
            try
            {
                DomainContext.EventFeedbacks.Add(EventFeedbackNew);
                DomainContext.SubmitChanges();
            }
            catch (Exception exc)
            {
                string message = exc.InnerException.ToString();
                System.Windows.MessageBox.Show(message);
            }
        }

        public void UpdateEventFeedback()
        {
            DomainContext.SubmitChanges();
        }

        public void DeleteEvent(EventFeedback EventFeedback)
        {
            try
            {
                DomainContext.EventFeedbacks.Remove(EventFeedback);
                DomainContext.SubmitChanges();
            }
            catch (Exception exc)
            {
                string message = exc.InnerException.ToString();
                System.Windows.MessageBox.Show(message);
            }

        }   

        #endregion

        #region "ViewModel Properties"

        public int EventID
        {
            get { return MyModel.EventID; }
            set
            {
                if (MyModel.EventID != value)
                {
                    MyModel.EventID = value;
                    InvokePropertyChanged("EventID");
                }
            }
        }

        public string FeedbackType
        {
            get { return MyModel.FeedbackType; }
            set
            {
                if (MyModel.FeedbackType != value)
                {
                    MyModel.FeedbackType = value;
                    InvokePropertyChanged("FeedbackType");
                }
            }
        }

        public string FeedbackContent
        {
            get { return MyModel.FeedbackContent; }
            set
            {
                if (MyModel.FeedbackContent != value)
                {
                    MyModel.FeedbackContent = value;
                    InvokePropertyChanged("FeedbackContent");
                }
            }
        }


        #endregion
    }
}
